
const app = getApp()
Page({
    data:
      {
        latitude: 0,   //经纬度
        longitude: 0,
        markers: [],
        mapControls:    //地图控件
          [
            { //定位
              id: 0,
              position: {                 //相对定位
                left: app.globalData.scWidth * 0.03,
                top: app.globalData.scHeight * 0.9,
                width: 50,
                height: 50
              },
              iconPath: "../../static/images/map/locat.png",          //相对于当前文件的路径
              clickable: true
            },
            {   //地图中心
              id: 14,
              position: {                 //相对定位
                left: app.globalData.scWidth * 0.47,
                top: app.globalData.scHeight * 0.42,
                width: 50,
                height: 50
              },
              iconPath: "../../static/images/map/center.png",
              clickable: false
            }
          ]
      },
    getLocation: function () {       //获取当前位置，并移动地图到当前位置
      this.myMapCtx.moveToLocation()
    },
    onLoad: function (options) {           //加载
      this.myMapCtx = wx.createMapContext("myMap", this)
      // 实例化API核心类
      this.setData({
        latitude: options.latitude,
        longitude: options.longitude
      })
      //this.getLocation()
    },
    mapControlTap: function (e) {          //地图控件点击
      switch (e.controlId) {
        case 0://定位
          this.getLocation()
          break;
        case 2://扫码
          this.scanCode()
          break;
        case 3://我的
          this.navigateToPersonal()
          break;
      }
    },
  })